package besta.moon.datastruct;

public class LongList {

    private int size;
    private long[] data;

    public LongList() {
        this(16);
    }

    LongList(int initialSize) {
        data = new long[initialSize];
    }

    public final int size() {
        return size;
    }

    public final long get(int idx) {
        if (idx >= size) {
            throw new IndexOutOfBoundsException("Index: " + idx + ", Size: " + size);
        }
        return data[idx];
    }

    public final void add(long value) {
        if (size >= data.length) {
            resize(size << 1);
        }
        data[size++] = value;
    }

    public final void clear() {
        size = 0;
    }

    private void resize(int newSize) {
        long[] dataNew = new long[newSize];
        System.arraycopy(data, 0, dataNew, 0, size);
        data = dataNew;
    }

}
